package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {

    @Select("select ORDERDATE,number,RESERVATIONS from t_ordersetting where ORDERDATE between #{beginDate} and #{endDate}")
    List<Map> findSettingData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Update("update t_ordersetting set number =#{number} where orderDate=#{orderDate}")
    Boolean updateNumberByOrderdate(@Param("number") int number, @Param("orderDate") String orderDate);

    @Select("select count(1) from t_ordersetting where RESERVATIONS < NUMBER and ORDERDATE=#{orderDate}")
    int isOrderOk(String orderDate);

    @Update("update t_ordersetting set RESERVATIONS = RESERVATIONS + 1 where ORDERDATE=#{orderDate}")
    void updateReservetionsByOrderDate(String orderDate);
}
